package com.dc.bobaoge.project.v3.to.v2.business.core.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * AdvertisementCommonUtil
 *
 * @author chenxueli
 * @date 2024-01-13 10:47:00
 */
public class AdvertisementCommonUtil {

    public static class MoldChannelShip {

        private static final List<Item> MOLD_CHANNEL_SHIP_LIST = new ArrayList<>();
        private static final Map<Integer, Long> MOLD_CHANNEL_MAP = new HashMap<>();
        private static final Map<Long, Integer> CHANNEL_MOLD_MAP = new HashMap<>();

        static {
            add(1, 1L);
            add(2, 2L);
            add(4, 3L);
            add(5, 4L);
            add(6, 5L);
            add(7, 6L);
            add(8, 7L);
            // 执行解析
            MOLD_CHANNEL_SHIP_LIST.forEach(moldChannelShip -> {
                MOLD_CHANNEL_MAP.put(moldChannelShip.getMold(), moldChannelShip.getChannel());
                CHANNEL_MOLD_MAP.put(moldChannelShip.getChannel(), moldChannelShip.getMold());
            });
        }

        /**
         * 添加信息
         *
         * @param mold    区域
         * @param channel 频道
         */
        private static void add(Integer mold, Long channel) {
            MOLD_CHANNEL_SHIP_LIST.add(new Item(mold, channel));
        }

        /**
         * 根据区域获取频道
         *
         * @param mold 区域
         * @return 频道
         */
        public static Long getChannelByMold(Integer mold) {
            return MOLD_CHANNEL_MAP.get(mold);
        }

        /**
         * 根据区域获取频道
         *
         * @param channel 频道
         * @return 区域
         */
        public static Integer getMoldByChannel(Long channel) {
            return CHANNEL_MOLD_MAP.get(channel);
        }

        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        private static class Item {
            /**
             * 区域
             */
            private Integer mold;
            /**
             * 频道
             */
            private Long channel;
        }

    }

}
